﻿using System.ComponentModel;
using BomComparison.Algorithm;
using BomComparison.Algorithm.Comparers;
using BomComparison.Core.Interface;
using BomComparisonModule.ViewModels.ResultDialog;
using BomComparisonModule.Views;
using BomComparisonModule.Views.ResultDialog;
using Excel.EPPlus;

namespace BomComparisonModule
{
    public class BomComparisonModule : IModule
    {
        private readonly IRegionManager _regionManager;
        private readonly IUnityContainer _container;

        public BomComparisonModule(
            IRegionManager regionManager,
            IUnityContainer container)
        {
            _regionManager = regionManager;
            _container = container;
        }

        public void OnInitialized(IContainerProvider containerProvider)
        {
            // 区域注册示例（如需）
            //var regionManager = containerProvider.Resolve<IRegionManager>();
            //_regionManager.RegisterViewWithRegion("MainWindow.ModuleContentRegion", typeof(FileSelectBrowserView));

        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // ================== 服务注册 ==================
            // 注册 IExcelReader 服务
            containerRegistry.Register<IExcelReader, ExcelReader>();
            containerRegistry.Register<IBomComparisonService, CompareByPartNumber>("CompareByPartNumber");
            containerRegistry.Register<IBomComparisonService, CompareByPartReference>("CompareByPartReference");
            containerRegistry.Register<IExcelWriter, ExcelWriter>();


            // 如果需要根据条件注册不同的实现，可以使用以下代码：
            // if (config.UseNpoi)
            // {
            //     _container.RegisterType<IExcelReader, NpoiExcelReader>();
            // }
            // else
            // {
            //     _container.RegisterType<IExcelReader, EPPlusExcelReader>();
            // }

            // 算法服务注册
            //containerRegistry.Register<IBomComparisonService, BomComparisonService>();

            // 协调器注册
            //containerRegistry.Register<IBomComparisonCoordinator, BomComparisonCoordinator>();

            // 事件聚合器（Prism自带，通常无需额外注册）
            //containerRegistry.RegisterInstance<IEventAggregator>(EventAggregator.Default);

            // ================== 视图注册 ==================
            // 注册导航
            containerRegistry.RegisterForNavigation<FileSelectBrowserView>();
            containerRegistry.RegisterForNavigation<BOM1View>();
            containerRegistry.RegisterForNavigation<BOM2View>();
            containerRegistry.RegisterForNavigation<BOMDiffView>();

            // 注册对话框
            containerRegistry.RegisterDialog<ShowResultView, ShowResultViewModel>("ShowResultDialog");
        }
    }
}
